package com.geekaca.d4.d3;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class TestInstant {
    public static void main(String[] args) {
        /**
         * JDK8 的时间戳获取方式
         */
        Instant now = Instant.now();
        System.out.println(now);
        long epochSecond = now.getEpochSecond();
        long l = System.currentTimeMillis();
        System.out.println("时间戳: " + epochSecond);
        System.out.println("System.currentTimeMillis: " + l);
        //中国所在时区 +8区
        Instant instant1 = Instant.now();
        ZonedDateTime zonedDateTime = instant1.atZone(ZoneId.systemDefault());
        System.out.println("当前所在时间时间为:" + zonedDateTime);
        // Instant => Date;
        Date date = Date.from(instant1);
        System.out.println(date);
        // Date => Instant;
        Instant instant2 = date.toInstant();
        System.out.println(instant2);
        System.out.println(instant2.getNano());
    }
}
